package com.boot.main.response;

import com.boot.main.utils.IsNotEmptyUtil;

import java.util.HashMap;

public class ResponseDataUtil {
    public static <T> ResponseData response(Integer code, String msg, T data){
        ResponseData responseData = new ResponseData();
        responseData.setCode(code);
        responseData.setMsg(msg);
        if(IsNotEmptyUtil.isEmpty(data)){
            HashMap map = new HashMap();
            // map.put("code", 401);
            responseData.setData(map);
        }else{
            responseData.setData(data);
        }
        return responseData;
    }

    public static <T> ResponseData success(String msg, T data){
        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        responseData.setMsg(msg);
        if(IsNotEmptyUtil.isEmpty(data)){
            HashMap map = new HashMap();
            // map.put("code", 401);
            responseData.setData(map);
        }else{
            responseData.setData(data);
        }
        return responseData;
    }

    public static <T> ResponseData error(String msg, T data){
        ResponseData responseData = new ResponseData();
        responseData.setCode(400);
        responseData.setMsg(msg);
        if(IsNotEmptyUtil.isEmpty(data)){
            HashMap map = new HashMap();
            // map.put("code", 401);
            responseData.setData(map);
        }else{
            responseData.setData(data);
        }
        return responseData;
    }
}
